//模拟post提交
function openWindowWithPost(url, name, keys, values) {
    var params=keys.split(',');
    var paramvalues=values.split(',')
    var html = "";
    html += "<html><head></head><body><form id='formid' accept-charset='UTF-8' method='post' action='"    + url + "'>";
    if (params && paramvalues && (params.length == paramvalues.length)){
        for ( var i = 0; i < params.length; i++){
            html += "<input type='hidden' name='" + params[i] + "' value='" + paramvalues[i] + "'/>";
        }
    }
    html += "</form><script type='text/javascript'>document.getElementById(\"formid\").submit()</script></body></html>";
    var newWindow = window.open(url, name);
    newWindow.document.write(html);
    return newWindow;
}
/**
 * 模拟post提交，不打开新页面
 * @param url 表单提交url
 * @param params 参数（json结构）
 * target _blank(新窗口打开)、_self（当前窗口打开）
 */
function postcall( url, params){
    var tempform = document.createElement("form");
    tempform.action = url;
    tempform.method = "post";
    tempform.style.display="none"
    tempform.target = "_blank";	
    for (var x in params) {
        var opt = document.createElement("input");
        opt.name = x;
        opt.value = params[x];
        tempform.appendChild(opt);
    }
    var opt = document.createElement("input");
    opt.type = "submit";
    tempform.appendChild(opt);
    document.body.appendChild(tempform);
    tempform.submit();
    document.body.removeChild(tempform);
}

/**
 * 模拟post提交，不打开新页面
 * @param url
 * @param name
 * @param keys
 * @param values
 */
function imitatePostSubmit(url, name, keys, values) {
    var params=keys.split(',');
    var paramvalues=values.split(',')
    var html = "";
    html += "<html><head></head><body><form id='formid' accept-charset='UTF-8' method='post' action='"    + url + "'>";
    if (params && paramvalues && (params.length == paramvalues.length)){
        for ( var i = 0; i < params.length; i++){
            html += "<input type='hidden' name='" + params[i] + "' value='" + paramvalues[i] + "'/>";
        }
    }
    html += "</form><script type='text/javascript'>document.getElementById(\"formid\").submit()</script></body></html>";
    window.document.write(html);
}

/******************************* checkBox begin ************************************/
/**
 * 全选按钮点击事件
 *
 * @param node 全选按钮(this)
 * @param checkboxname 多选框名
 */
function changeAllCheckBox(node, checkboxname) {
    if (node.checked) {
        selectAllCheckBox(checkboxname);
    } else {
        clearAllCheckBox(checkboxname);
    }
}

/**
 * 取消全选多选框
 * @param checkboxname 多选框名称
 */
function clearAllCheckBox(checkboxname) {
    $("input[name='" + checkboxname + "']").prop('checked', false);
}

/**
 * 全选多选框
 * @param checkboxname 多选框名称
 */
function selectAllCheckBox(checkboxname) {
    $("input[name='" + checkboxname + "']").prop('checked', true);
}

/**
 * 获取多选框被选中的元素
 * @param checkboxname 多选框名称
 */
function getCheckedNodes(checkboxname) {
    var $checkbox = $("input[name='" + checkboxname + "']:checked");
    return $checkbox;
}

/**
 * 获取多选框选中的多个值
 * @param checkboxname 多选框名称
 */
function getCheckboxVal(checkboxname) {
    var str = "";
    $("input[name='" + checkboxname + "']:checked").each(function () {
        str += "," + $(this).val();
    });

    if (str.length > 0) {
        str = str.substring(1);
    }
    return str;
}

/**
 * 获取多选框被选中一个的值
 * @param checkboxname 多选框名称
 */
function getCheckboxOnlyOneVal(checkboxname) {
    var str = "";
    var $checkbox = $("input[name='" + checkboxname + "']:checked");
    var len = $checkbox.length;
    if (len == 1) {
        str = $checkbox.val()
    }
    return str;
}

/******************************* checkBox end ************************************/

/**
 * 
 * {
		icon:"error",
    	title:"保存提示框",
		msg:"抱歉,保存失败!",
		okButton:"ok",
		okCallback:function(){
			console.log("To:http://www.baidu.com");
		}
    }
 */
function showAlert(opt) {
	var dialog = new ShowAlertDialog(opt);
	dialog.show();
}

/**
 * 
 * {
		icon:"info",
    	title:"确认框",
		msg:"是否确定要删除?",
		okButton:"是",
		cancelButton:"否",
		confirmCallback:function(isOk){
			 if(isOk){
				 console.log("确认后执行...");
			 }else{
				 console.log("取消后执行...");
			 }
		}
    }
 * @param opt
 * @returns
 */

function showConfirm(opt) {
	var dialog = new ShowConfirmDialog(opt);
	dialog.show();
}

/**
 * @Title: blockUI
 * @Description: TODO 用于前台异步处理防死锁措施
 */
function blockUI(showContent, imgUrl) {
	var msg_content = "loading...";
	var img_url = ctx + "/img/common/loading-spinner-grey.gif";
	
	if(showContent!=null){
		msg_content = showContent;
	}
	
	if(imgUrl!=null){
		img_url = imgUrl;
	}
	
	$.blockUI({
		message:"<p style='margin-bottom:0;'><img class='mr5' src='"+img_url+"'/>"+msg_content+"</p>",
		css:{
			border:"3px solid #eee",
			opacity:".8",
		},
		overlayCSS:{
			opacity:"0.3",
			backgroundColor:"#555",
		}
	});	
}

/**
 * @Title: isEmpty
 * @Description: 验证主要必填内容是否为空
 */
function isEmpty(pointContent){
	if(pointContent == null || pointContent == undefined || pointContent.length <= 0 ||
			$.trim(pointContent).length <= 0 || pointContent == '无') return true;		
	return false;
}

//切换普通用户
function switchNormar(){
	window.location.href=ctx+"/normal/myasset/myassetlist";
}
//切换资产管理员系统
function switchManger(){
	window.location.href=ctx+"/manager/assetAccount/assetsAccountList";
}
